
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$title}</title>
    <style>
        * {
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        body {
            background: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background: white;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 400px;
        }
        h2 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
        }
        input {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        button {
            width: 100%;
            padding: 12px;
            background-color: #4285f4;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s;
        }
        button:hover {
            background-color: #3367d6;
        }
        .footer {
            text-align: center;
            margin-top: 20px;
            color: #777;
        }
        a {
            color: #4285f4;
            text-decoration: none;
        }
        .error {
            color: #d32f2f;
            font-size: 14px;
            margin-top: 5px;
        }
        #remember_login{
            width: 40px;
        }
         #remember_txt{
            display: inline-block;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>用户登录</h2>
        <!-- <form id="loginForm" onsubmit="return validateForm()"> -->
        <form id="loginForm" action="{:url('login')}" method="post" onsubmit="return validateForm()">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="login" placeholder="请输入用户名">
                <div id="usernameError" class="error"></div>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="请输入密码">
                <div id="passwordError" class="error"></div>
            </div>
            <div class="form-group">
                <img id="verify_img" src="/admin/captcha" alt="验证码" onclick="refreshVerify()">
                <input class='yz_input' name="captcha" placeholder="验证码" type="text"/>
            </div>
            <div class="form-group">
                <input type="checkbox" id="remember_login">
                <label for="remember_login" id="remember_txt">记住账号</label>
            </div>
            <button type="submit" id="form_btn">登录</button>
        </form>
        <div class="footer">
            没有账号？<a href="#">立即注册</a>
        </div>
    </div>

    <script>
        function refreshVerify() {
            var ts = Date.parse(new Date()) / 1000;
            var img = document.getElementById('verify_img');
            img.src = "/admin/captcha?id=" + ts;
        }
        $(function () {
            $("#form_btn").click(function () {

                let isValid = true;
                const username = document.getElementById('username').value.trim();
                const password = document.getElementById('password').value.trim();
                
                // 清空错误信息
                document.getElementById('usernameError').textContent = '';
                document.getElementById('passwordError').textContent = '';
                
                // 验证用户名
                if (username === '') {
                    document.getElementById('usernameError').textContent = '用户名不能为空';
                    isValid = false;
                } else if (username.length < 4) {
                    document.getElementById('usernameError').textContent = '用户名至少4个字符';
                    isValid = false;
                }
                
                // 验证密码
                if (password === '') {
                    document.getElementById('passwordError').textContent = '密码不能为空';
                    isValid = false;
                } else if (password.length < 6) {
                    document.getElementById('passwordError').textContent = '密码至少6个字符';
                    isValid = false;
                }
                
                if (isValid) {
                    alert('登录验证通过，即将提交表单');
                    // 这里可以添加实际的表单提交逻辑
                    $("#loginForm").ajaxSubmit(function (txt) {
                        //alert(JSON.stringify(txt))
                        if (txt.code == 1) {
                            //记住账号
                            if($("#remember_login").is(':checked')){
                                var login = $("input[name=login]").val();
                                setCookie('remember_login',login);
                            }
                            window.location.href = '{:url("/admin/index/index")}'
                        } else {
                            refreshVerify();
                            alert(txt.msg)
                        }
                    });
                }
            })
            $('.yz_input').bind('keyup', function(event) {
                if (event.keyCode == "13") {
                    //回车执行查询
                    $('#form_btn').click();
                }
            });
        })
    </script>
</body>
</html>
